﻿using System.Net.Http;
using System.Net.Http.Formatting;
using System.Net.Http.Headers;
using Newtonsoft.Json.Serialization;
using Sustainalytics.Entities.ESGRatings;
using Sustainalytics.ESGRatings.DataContract.ESG;

using Xunit.Abstractions;
using Xunit;

namespace Sustainalytics.ESGComputing.Service.Tests
{

    public class ESGAggregationTest : Disposable
    {

        private readonly ITestOutputHelper _output;
        private HttpClient _sutClient;
        private const string SutLink = "http://localhost:10280/esgcomputingserv/api/v1";
        private static readonly string _sutLink = string.Format("{0}{1}", SutLink, "/esgcompute");
        private bool _disposed;
        private static readonly JsonMediaTypeFormatter JsonMediaTypeFormatter = new JsonMediaTypeFormatter
        {
            SerializerSettings = { ContractResolver = new CamelCasePropertyNamesContractResolver() }
        };

        private RankingDataFixture _dataFixture;


        public ESGAggregationTest(RankingDataFixture fixture, ITestOutputHelper output)
        {
            _dataFixture = fixture;
            _output = output;
            _sutClient = new HttpClient();
            _sutClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
        }

        ~ESGAggregationTest()
        {
            Dispose(false);
        }


        [Fact]
        public void ESGComputeController_Post_Validate_Overall_Score_Average()
        {



            int referenceUniverseIndex = 0;
            int matrixIndex = 0;
            //Arrange

            var options = new ESGRatingsOptionsDto()
            {
                RefUnivId = _dataFixture.ReferenceUniverses[referenceUniverseIndex].Id,
                MatrixId = _dataFixture.Matrices[matrixIndex].MatrixId,
                TemplateType = TemplateTypeEnum.Combined,
                CompanyType = CompanyTypeEnum.Combined,
                GroupBy = ComparativeGroupEnum.PeerGroup,
            };





            //Act
            var result = _sutClient.PostAsync(_sutLink, options, JsonMediaTypeFormatter);

            var esgRatingsDto = result.Result.Content.ReadAsAsync<ESGRatingsDto>(JsonMediaTypeFormatter.Yield());



        }
    }



}


